﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Compression;
using System.IO;

using log4net;
using AKMII.DMRA.DataAccess;

namespace AKMII.DMRA.DataLoader
{
    public class Decompressor
    {
        /// <summary>
        /// decompress files to the target directory
        /// </summary>
        /// <param name="files">files to be decompressed</param>
        /// <param name="destPath">destination directory</param>
        //private bool Decompress(string file, string destPath)
        //{
        //    try
        //    {
        //        if (file != null && file.EndsWith(".zip", StringComparison.CurrentCultureIgnoreCase))
        //        {
        //            Utility.Unzip(file, destPath);
        //        }
        //        else
        //        {
        //            throw new ArgumentException("unsupport compressed file type: " + file);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("Exception occurs in decompress process", ex);
        //        return false;
        //    }

        //    return true;
        //}

        //public void Process(string source, string destination)
        //{
        //    if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(destination))
        //    {
        //        if (source.EndsWith(@"\") && destination.EndsWith(@"\"))
        //        {
        //            DirectoryInfo di = new DirectoryInfo(source);
        //            FileInfo[] fi = di.GetFiles("*.zip");

        //            CommandHistoryAccessor accessor = new CommandHistoryAccessor();
        //            DateTime dateTime = accessor.GetLastExecuteTime(Command.Decompress.ToString());

        //            foreach (FileInfo file in fi)
        //            {
        //                if (file.LastWriteTime > dateTime)
        //                {
        //                    if (this.Decompress(source + file.Name, destination))
        //                    {
        //                        accessor.UpdateLastExecuteTime(Command.Decompress.ToString(), DateTime.Now);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}
    }
}
